package edu.cuit.avatar.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/14 16:13
 */
public class ComparatorTest {
    public static void main(String[] args) {
        List<Circle> circles = new ArrayList<>();
        circles.add(new Circle(5));
        circles.add(new Circle(15));
        circles.add(new Circle(8));
        circles.add(new Circle(35));
        circles.add(new Circle(20));

        //排序:针对集合的工具类 Collections
        Collections.sort(circles); //使用自然排序(元素是自然可比较的----Comparable)
        for(var circle : circles)
            System.out.println(circle);

        System.out.println("======使用比较排序(外部)排序===============");
//        Collections.sort(circles, (o1, o2) -> -Float.compare(o1.getRadius(), o2.getRadius()));
//
//        for(var circle : circles)
//            System.out.println(circle);

        Collections.sort(circles, Collections.reverseOrder());
        for(var circle : circles)
           System.out.println(circle);

    }
}
